Skip to content

Properly cancel threads that execute tests before closing the terminal#132

Merged
pedjaradenkovic merged 4 commits intomainfrom
fix/decrease-exit-time
Mar 25, 2026
Merged

Properly cancel threads that execute tests before closing the terminal#132
pedjaradenkovic merged 4 commits intomainfrom
fix/decrease-exit-time

Conversation

@pedjaradenkovic
Copy link
Copy Markdown
Contributor

In #124 the problem with quitting the terminal is solved.

Nevertheless, it was noticed when developing scraping software with playwright tests that are executed for a long time, the tests that are run are not canceled. This caused that even computer was completely blocked with a couple of runs.

This implementation also handles sigterm properly in headless mode.

How to test this:

Create slow running script test:

 # slow_test.sh
  #!/bin/bash
  echo "test script started, PID=$$"
  sleep 60
  echo "test script completed" >> /tmp/codeplain_test_completed.txt

and chmod +x slow_test.sh

and reference it from config file. Run the rendering and exit when running unit test script (ctrl +d)

On main:
grep -af slow_test should return PID

On this branch:

  pgrep -a sleep         # should return nothing
  pgrep -af slow_test    # should return nothing

Note: When canceling the render, there are other actions that might not be terminated properly - REST API calls, writing files or git commits. But we actually don't care of them as we are restarting only from certain git check points.

@pedjaradenkovic pedjaradenkovic requested a review from VitjanZ March 14, 2026 00:37
@pedjaradenkovic pedjaradenkovic force-pushed the fix/decrease-exit-time branch 3 times, most recently from 4c7dbb3 to 13f432f Compare March 14, 2026 00:48
@pedjaradenkovic pedjaradenkovic self-assigned this Mar 14, 2026
@VitjanZ
Copy link
Copy Markdown
Collaborator

VitjanZ commented Mar 17, 2026

Looks good!

I just added a small fix by switching the ordering of the following:
_kill_process(proc)
partial_stdout = proc.stdout.read()

The problem was that if you call proc.stdout.read before _kil_process it might wait for EOF which can mess with the test script timeout. You can test this by using your example slow_test.sh script. Run it with "--test-script-timeout 5" and see that it will run for 60 seconds waiting for the sleep to finish.

Copy link
Copy Markdown
Collaborator

@VitjanZ VitjanZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review the small fix I added otherwise this seems good to me.

@pedjaradenkovic pedjaradenkovic force-pushed the fix/decrease-exit-time branch from 101a8eb to e358d5d Compare March 24, 2026 13:30
@pedjaradenkovic pedjaradenkovic force-pushed the fix/decrease-exit-time branch from ab2e447 to 8398777 Compare March 24, 2026 20:52
@pedjaradenkovic pedjaradenkovic merged commit cf48318 into main Mar 25, 2026
10 checks passed
@pedjaradenkovic pedjaradenkovic deleted the fix/decrease-exit-time branch March 25, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants